package com.tmeone.erpone.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class PageController {

    @GetMapping("favicon.ico")
    @ResponseBody
    void noFaviconIco() {
        //处理没有favicon.ico的问题
    }

    @RequestMapping("{page}")
    public String page(@PathVariable String page){
        return page;
    }

    @RequestMapping("{path}/{page}")
    public String page(@PathVariable String path, @PathVariable String page){
        return path + "/" + page;
    }

    @RequestMapping("/login")
    public String toLogin() {
        return "login";
    }

    @RequestMapping({"/logout1"})
    public void logout(HttpServletRequest request, HttpServletResponse response) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null) {//清除认证
            new SecurityContextLogoutHandler().logout(request, response, auth);
        }
        System.out.println("hhhhhhhh");


    }

}
